home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / SNNSV32.ZIP / SNNSv3.2 / xgui / sources / ui_result.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-25  |  13.5 KB  |  456 lines

  1. /*****************************************************************************
  2.   FILE           : ui_result.c
  3.   SHORTNAME      : result.c
  4.   SNNS VERSION   : 3.2
  5.  
  6.   PURPOSE        : creation and management of result file widget
  7.  
  8.   AUTHOR         : Michael Vogt
  9.   DATE           : 20.5.1992
  10.  
  11.   CHANGED BY     :
  12.   IDENTIFICATION : @(#)ui_result.c    1.14 4/6/94
  13.   SCCS VERSION   : 1.14
  14.   LAST CHANGE    : 4/6/94
  15.  
  16.              Copyright (c) 1990-1994  SNNS Group, IPVR, Univ. Stuttgart, FRG
  17.              
  18. ******************************************************************************/
  19.  
  20. #include <stdlib.h>
  21. #include <stdio.h>
  22.  
  23. #include "ui.h"
  24.  
  25. #include "krui_typ.h"
  26.  
  27. #include <X11/Xaw/Form.h>
  28. #include <X11/Xaw/Box.h>
  29. #include <X11/Xaw/Toggle.h>
  30. #include <X11/Xaw/Cardinals.h>
  31. #include <X11/Xaw/SimpleMenu.h>
  32. #include <X11/Xaw/SmeBSB.h>
  33. #include <X11/Xaw/SmeLine.h>
  34.  
  35. #include "ui_xWidgets.h"
  36. #include "ui_confirmer.h"
  37. #include "ui_main.h"
  38. #include "ui_mainP.h"
  39. #include "ui_netUpdate.h"
  40. #include "ui_textP.h"
  41. #include "ui_fileP.h"
  42. #include "ui_utilP.h"
  43. #include "kr_ui.h"
  44. #include "ui_action.h"
  45. #include "ui_remote.h"
  46. #include "ui_result.ph"
  47.  
  48.  
  49. /*****************************************************************************
  50.   FUNCTION : ui_performRadioButtons
  51.  
  52.   PURPOSE  : toggles the buttons in an array of toggle buttons
  53.   RETURNS  : void
  54.   NOTES    :
  55.  
  56.   UPDATE   : 20.5.1992
  57. *****************************************************************************/
  58.  
  59. static void ui_performRadioButtons (Widget array[], int size, int button)
  60.  
  61. {
  62.     int    i;
  63.  
  64.     for (i=0; i<size; i++)
  65.         ui_xSetToggleState(array[i], FALSE);
  66.     ui_xSetToggleState(array[button], TRUE);
  67. }
  68.  
  69.  
  70. /*****************************************************************************
  71.   FUNCTION : ui_result_Setinput
  72.  
  73.   PURPOSE  : callback for yes/no radio buttons of input patterns
  74.   RETURNS  : void
  75.   NOTES    :
  76.  
  77.   UPDATE   : 20.5.1992
  78. ******************************************************************************/
  79.  
  80. static void ui_result_Setinput (Widget w, int button, caddr_t call_data)
  81.  
  82. {
  83.     ui_performRadioButtons(ui_resultInputRButtons, 2, button);
  84.     ui_result_input_state = button;
  85. }
  86.  
  87.  
  88. /*****************************************************************************
  89.   FUNCTION : ui_result_Setoutput
  90.  
  91.   PURPOSE  : callback for yes/no radio buttons of output patterns
  92.   RETURNS  : void
  93.   NOTES    :
  94.  
  95.   UPDATE   : 20.5.1992
  96. ******************************************************************************/
  97.  
  98. static void ui_result_Setoutput (Widget w, int button, caddr_t call_data)
  99.  
  100. {
  101.     ui_performRadioButtons(ui_resultOutputRButtons, 2, button);
  102.     ui_result_output_state = button;
  103. }
  104.  
  105.  
  106. /*****************************************************************************
  107.   FUNCTION : ui_result_Setmode
  108.  
  109.   PURPOSE  : callback for create/append file mode selection
  110.   RETURNS  : void
  111.   NOTES    :
  112.  
  113.   UPDATE   : 20.5.1992
  114. ******************************************************************************/
  115.  
  116. static void ui_result_Setmode (Widget w, int button, caddr_t call_data)
  117.  
  118. {
  119.     ui_performRadioButtons(ui_resultModeRButtons, 2, button);
  120.     ui_result_mode_state = button;
  121. }
  122.  
  123.  
  124. /*****************************************************************************
  125.   FUNCTION : ui_result_lastcall
  126.  
  127.   PURPOSE  : callback for setting of values of last call
  128.   RETURNS  : void
  129.   NOTES    :
  130.  
  131.   UPDATE   : 20.5.1992
  132. ******************************************************************************/
  133.  
  134. static void ui_result_lastcall (Widget w, int dummy, caddr_t call_data)
  135.  
  136. {
  137.     char    buf[20];
  138.     ui_performRadioButtons(ui_resultInputRButtons, 2, ui_result_input_state);
  139.     ui_performRadioButtons(ui_resultOutputRButtons, 2, ui_result_output_state);
  140.     ui_performRadioButtons(ui_resultModeRButtons, 2, ui_result_mode_state);
  141.     sprintf(buf,"%d", ui_result_no_start_pat);
  142.     ui_xSetString(ui_resultStartPattern, buf);
  143.     sprintf(buf,"%d", ui_result_no_end_pat);
  144.     ui_xSetString(ui_resultEndPattern, buf);
  145. }
  146.  
  147.  
  148. /*****************************************************************************
  149.   FUNCTION : ui_result_default
  150.  
  151.   PURPOSE  : callback for setting of default values
  152.   RETURNS  : void
  153.   NOTES    :
  154.  
  155.   UPDATE   : 20.5.1992
  156. ******************************************************************************/
  157.  
  158. static void ui_result_default (Widget w, int dummy, caddr_t call_data)
  159.  
  160. {
  161.     ui_result_input_state = UI_RESULT_INPUT_YES;
  162.     ui_result_output_state = UI_RESULT_OUTPUT_NO;
  163.     ui_result_mode_state = UI_RESULT_MODE_CREATE;
  164.     ui_result_no_start_pat = 1;
  165.     ui_result_no_end_pat = krui_getNoOfPatterns();
  166.     ui_result_lastcall (w, dummy, call_data);
  167. }
  168.  
  169.  
  170. /*****************************************************************************
  171.   FUNCTION : ui_resultDone
  172.  
  173.   PURPOSE  : callback for closing result file panel
  174.   RETURNS  : void
  175.   NOTES    :
  176.  
  177.   UPDATE   : 20.5.1992
  178. ******************************************************************************/
  179.  
  180. static void ui_resultDone (Widget w, int dummy, caddr_t call_data)
  181.  
  182. {
  183.     char string[80+MAX_NAME_LENGTH+MAX_NAME_LENGTH];
  184.     char filename[4+MAX_NAME_LENGTH+MAX_NAME_LENGTH];
  185.     Bool performSave = TRUE;
  186.     int maxNpos;
  187.  
  188.     ui_result_no_start_pat = ui_xIntFromAsciiWidget(ui_resultStartPattern);
  189.     ui_result_no_end_pat = ui_xIntFromAsciiWidget(ui_resultEndPattern);
  190.  
  191.     if (ui_result_no_start_pat < 1 ||
  192.     ui_result_no_end_pat > krui_getNoOfPatterns() ||
  193.     ui_result_no_start_pat > ui_result_no_end_pat)
  194.     {
  195.     ui_confirmOk("No such pattern numbers");
  196.     return;
  197.     }
  198.  
  199.     if (strlen(ui_filenameRES) == 0) {
  200.         ui_confirmOk("No file specified!");
  201.     ui_popupDone(w, UI_POPUP_RESULT, call_data);
  202.         return;
  203.     }
  204.  
  205.     if (ui_filenameRES[0] == '/')
  206.         sprintf(filename, "%s%s", ui_filenameRES, 
  207.                 ui_getExtension(UI_FILE_RES));
  208.     else
  209.         sprintf(filename, "%s/%s%s", ui_pathname, ui_filenameRES, 
  210.                 ui_getExtension(UI_FILE_RES));
  211.  
  212.     if (ui_fileExist(filename, 0) &&
  213.     ui_result_mode_state == UI_RESULT_MODE_CREATE) 
  214.     {
  215.         sprintf(string,"%s already exist! Overwrite?", ui_filenameRES);
  216.         performSave = ui_confirmYes(string);
  217.     }
  218.     
  219.     if (performSave) 
  220.     {
  221.     ui_printMessage("Saving result file ...");
  222.     ui_rem_getSubPatPanel();
  223.     ui_checkError(krui_DefTrainSubPat(subIPatSize,subOPatSize,
  224.                       subIPatStep,subOPatStep,&maxNpos));
  225.  
  226.     /* to ensure that the subpattern fits the network, try one step */
  227.     ui_checkError(krui_DefShowSubPat(subIPatSize,subOPatSize,
  228.                      subIPatPos,subOPatPos));
  229.     ui_checkError(krui_showPattern(OUTPUT_NOTHING));
  230.  
  231.     if (ui_kernelError == 0)
  232.         ui_checkError(krui_saveResult(filename,
  233.         ui_result_mode_state == UI_RESULT_MODE_CREATE,
  234.         ui_result_no_start_pat,
  235.         ui_result_no_end_pat,
  236.         ui_result_input_state == UI_RESULT_INPUT_YES,
  237.         ui_result_output_state == UI_RESULT_OUTPUT_YES));
  238.  
  239.     if (ui_kernelError < 0)
  240.     {
  241.             ui_confirmOk("Error during saving result file!");
  242.         ui_printMessage("");
  243.     }
  244.         else 
  245.     {
  246.         if (ui_result_mode_state == UI_RESULT_MODE_CREATE)
  247.                 sprintf(string, "Result saved to file:\n   %s\n", filename);
  248.         else
  249.         sprintf(string, "Result appended to file:\n   %s\n", filename);
  250.             ui_tw_printMessage(string);
  251.         ui_printMessage("Result file saved.");
  252.         }
  253.     ui_net_completeRefresh(NULL, UI_GLOBAL);
  254.     }
  255.     ui_popupDone(w, UI_POPUP_RESULT, call_data);
  256. }
  257.  
  258.  
  259. /*****************************************************************************
  260.   FUNCTION : ui_resultCancel
  261.  
  262.   PURPOSE  : callback for closing result file panel without doing anything
  263.   RETURNS  : void
  264.   NOTES    :
  265.  
  266.   UPDATE   : 20.5.1992
  267. ******************************************************************************/
  268.  
  269. static void ui_resultCancel (Widget w, int dummy, caddr_t call_data)
  270.  
  271. {
  272.     ui_result_no_start_pat = ui_xIntFromAsciiWidget(ui_resultStartPattern);
  273.     ui_result_no_end_pat = ui_xIntFromAsciiWidget(ui_resultEndPattern);
  274.     ui_popupDone(w, UI_POPUP_RESULT, call_data);
  275. }
  276.  
  277.  
  278. /*****************************************************************************
  279.   FUNCTION : ui_xCreateResultPanel
  280.  
  281.   PURPOSE  : creates a form widget for all result file elements 
  282.   RETURNS  : the created widget
  283.   NOTES    : some constants are used (see below) to get a relativ positioning
  284.              of the items. This is VERY useful after changings.
  285.  
  286.   UPDATE   : 20.5.1992
  287. *****************************************************************************/
  288.  
  289. static Widget ui_xCreateResultPanel (Widget parent)
  290.  
  291. {
  292.     Widget    /* topLabel, */ startLabel, endLabel, inputLabel, outputLabel,
  293.         createappendLabel, panel;
  294.  
  295.     int  fontWidth = 8;
  296.  
  297.     int  startWidth     =  25 * fontWidth;
  298.     int  includeWidth =  25 * fontWidth;
  299.     int  numberWidth = 7 * fontWidth;
  300.  
  301.     panel = XtCreateManagedWidget("rPanel", formWidgetClass, parent, 
  302.         NULL, ZERO);
  303.  
  304. /*
  305.     topLabel = ui_xCreateLabelItem("specify result file format:", panel,
  306.         titelWidth, NULL, NULL);
  307. */
  308.  
  309.     startLabel = ui_xCreateLabelItem("start pattern :", panel,
  310.         startWidth, NULL, NULL);
  311.  
  312.     ui_resultStartPattern = ui_xCreateDialogItem("startPattern", panel,
  313.         " ", numberWidth, startLabel, NULL);
  314.     
  315.     endLabel = ui_xCreateLabelItem("end pattern   :", panel,
  316.         startWidth, NULL, ui_resultStartPattern);
  317.  
  318.     ui_resultEndPattern = ui_xCreateDialogItem("endPattern", panel,
  319.         " ", numberWidth, endLabel, ui_resultStartPattern);
  320.     
  321.     createappendLabel = ui_xCreateLabelItem("result file mode :", 
  322.         panel, includeWidth, NULL, ui_resultEndPattern);
  323.  
  324.     ui_resultModeRButtons[UI_RESULT_MODE_CREATE] = 
  325.         ui_xCreateToggleItem("create", panel, NULL,
  326.         createappendLabel, ui_resultEndPattern);
  327.     XtAddCallback(ui_resultModeRButtons[UI_RESULT_MODE_CREATE], XtNcallback, 
  328.         (XtCallbackProc) ui_result_Setmode, (caddr_t) UI_RESULT_MODE_CREATE);
  329.  
  330.     ui_resultModeRButtons[UI_RESULT_MODE_APPEND] = 
  331.         ui_xCreateToggleItem("append", panel, NULL,
  332.         ui_resultModeRButtons[UI_RESULT_MODE_CREATE], 
  333.         ui_resultEndPattern);
  334.     XtAddCallback(ui_resultModeRButtons[UI_RESULT_MODE_APPEND], XtNcallback, 
  335.         (XtCallbackProc) ui_result_Setmode, (caddr_t) UI_RESULT_MODE_APPEND);
  336.  
  337.     inputLabel = ui_xCreateLabelItem("include input patterns  :", panel,
  338.         includeWidth, NULL, 
  339.         ui_resultModeRButtons[UI_RESULT_MODE_CREATE]);
  340.  
  341.     ui_resultInputRButtons[UI_RESULT_INPUT_YES] = 
  342.         ui_xCreateToggleItem("yes", panel, NULL,
  343.         inputLabel, ui_resultModeRButtons[UI_RESULT_MODE_CREATE]);
  344.     XtAddCallback(ui_resultInputRButtons[UI_RESULT_INPUT_YES], XtNcallback, 
  345.         (XtCallbackProc) ui_result_Setinput, (caddr_t) UI_RESULT_INPUT_YES);
  346.  
  347.     ui_resultInputRButtons[UI_RESULT_INPUT_NO] = 
  348.         ui_xCreateToggleItem("no", panel, NULL,
  349.         ui_resultModeRButtons[UI_RESULT_MODE_CREATE], 
  350.         ui_resultModeRButtons[UI_RESULT_MODE_APPEND]);
  351.     XtAddCallback(ui_resultInputRButtons[UI_RESULT_INPUT_NO], XtNcallback, 
  352.         (XtCallbackProc) ui_result_Setinput, (caddr_t) UI_RESULT_INPUT_NO);
  353.  
  354.     outputLabel = ui_xCreateLabelItem("include output patterns :", 
  355.         panel, includeWidth, NULL, 
  356.         ui_resultInputRButtons[UI_RESULT_INPUT_YES]);
  357.  
  358.     ui_resultOutputRButtons[UI_RESULT_OUTPUT_YES] = 
  359.         ui_xCreateToggleItem("yes", panel, NULL,
  360.         outputLabel, ui_resultInputRButtons[UI_RESULT_INPUT_YES]);
  361.     XtAddCallback(ui_resultOutputRButtons[UI_RESULT_OUTPUT_YES], XtNcallback, 
  362.         (XtCallbackProc) ui_result_Setoutput, (caddr_t) UI_RESULT_OUTPUT_YES);
  363.  
  364.     ui_resultOutputRButtons[UI_RESULT_OUTPUT_NO] = 
  365.         ui_xCreateToggleItem("no", panel, NULL,
  366.         ui_resultModeRButtons[UI_RESULT_MODE_CREATE], 
  367.         ui_resultInputRButtons[UI_RESULT_INPUT_NO]);
  368.     XtAddCallback(ui_resultOutputRButtons[UI_RESULT_OUTPUT_NO], XtNcallback, 
  369.         (XtCallbackProc) ui_result_Setoutput, (caddr_t) UI_RESULT_OUTPUT_NO);
  370.  
  371.     XawFormDoLayout(panel, TRUE);
  372.     ui_ResultIsCreated = TRUE;
  373.  
  374.     return panel;
  375. }
  376.  
  377.  
  378. /*****************************************************************************
  379.   FUNCTION : ui_popupResult
  380.  
  381.   PURPOSE  : popup a result file panel
  382.   RETURNS  : void
  383.   NOTES    :
  384.  
  385.   UPDATE   : 20.5.1992
  386. ******************************************************************************/
  387.  
  388. void ui_popupResult (Widget button)
  389.  
  390. {
  391.     Widget      doneButton, cancelButton, defaultButton;
  392.     Widget    ui_resultBox;
  393.     Widget    ui_resultPanel;
  394.     Arg        args[5];
  395.     Position    x, y;
  396.     Dimension    width, height;
  397.     Cardinal    n;
  398.     static Bool    first_call = TRUE;
  399.  
  400.     /* Upper left corner will be in the center of the calling button */
  401.  
  402.     if (NOT ui_ResultIsCreated) {
  403.  
  404.     n = 0;
  405.     XtSetArg(args[0], XtNwidth, &width); n++;
  406.     XtSetArg(args[1], XtNheight, &height); n++;
  407.     XtGetValues(button, args, n);
  408.     XtTranslateCoords(button, (Position) (width / 2), 
  409.               (Position) (height / 2),
  410.               &x, &y);
  411.  
  412.     n = 0;
  413.     XtSetArg(args[n], XtNx, x);    n++;
  414.     XtSetArg(args[n], XtNy, y);    n++;
  415.  
  416.     /* Now create Popup */
  417.  
  418.     ui_popResult = 
  419.         XtCreatePopupShell("result file format",
  420.          transientShellWidgetClass, ui_toplevel, args, n);
  421.  
  422.     ui_resultBox =
  423.         XtCreateManagedWidget("form", formWidgetClass, ui_popResult,
  424.                   NULL, ZERO);
  425.  
  426.     ui_resultPanel = ui_xCreateResultPanel(ui_resultBox);
  427.  
  428.     doneButton = ui_xCreateButtonItem("done", ui_resultBox, NULL,
  429.         ui_resultPanel);
  430.     XtAddCallback(doneButton, XtNcallback, (XtCallbackProc) ui_resultDone, (caddr_t) UI_POPUP_RESULT);
  431.  
  432.     cancelButton = ui_xCreateButtonItem("cancel", ui_resultBox, doneButton,
  433.         ui_resultPanel);
  434.     XtAddCallback(cancelButton, XtNcallback, (XtCallbackProc) ui_resultCancel, (caddr_t) UI_POPUP_RESULT);
  435.  
  436.     defaultButton = ui_xCreateButtonItem("default2", ui_resultBox,
  437.         cancelButton, ui_resultPanel);
  438.     XtAddCallback(defaultButton, XtNcallback, (XtCallbackProc) ui_result_default, NULL);
  439.  
  440.     ui_checkWindowPosition(ui_popResult);
  441.     XtPopup(ui_popResult, XtGrabExclusive);
  442.         ui_xDontResizeWidget(ui_popResult); 
  443.     if (first_call)
  444.     {
  445.         ui_result_default(NULL, (int) NULL, NULL);
  446.         first_call = FALSE;
  447.     }
  448.     else
  449.     {
  450.         ui_result_lastcall(NULL, (int) NULL, NULL);
  451.     }
  452.     }
  453. }
  454.  
  455.  
  456.